class Player extends Sprite
{
  
  private final float HANDGUN_DAMAGE = 10;
  private final float MACHINEGUN_DAMAGE = 10;
  private final float SHOTGUN_DAMAGE = 20;
  private final float SNIPER_DAMAGE = 100;
  private final float GRENADE_DAMAGE = 50;
  
  private final int HANDGUN_COUNTER = 10;
  private final int MACHINEGUN_COUNTER = 2;
  private final int SHOTGUN_COUNTER = 20; 
  private final int SNIPER_COUNTER = 40;  
  private final int GRENADE_COUNTER = 100;
  
  private final float PLAYER_SIZE = 5;
  
  private final int PLAYER_HEALTH = 100;
  
  private final int AMMO1 = 99999;
  private final int AMMO2 = 100;
  private final int AMMO3 = 30;
  private final int AMMO4 = 30;
  private final int AMMO5 = 3;
  
  private int[] weaponAmmo;
  
  private int shotCounter;
  public int currentWeapon;
  private int currentAmmo;
  
  private Terrain terrain;
  private GameCamera gameCamera;
  
  public Player(PVector location, GameCamera gameCamera)
  {
    this.location = location;
    this.gameCamera = gameCamera;
    this.terrain = terrain;
    this.spriteSize = PLAYER_SIZE*1.5;
    weaponAmmo = new int[5];

    init();
  }
  
  private void init()
  {
    weaponAmmo[0] = AMMO1;
    weaponAmmo[1] = AMMO2;
    weaponAmmo[2] = AMMO3;
    weaponAmmo[3] = AMMO4;
    weaponAmmo[4] = AMMO5;
    
    currentAmmo = weaponAmmo[0];
    damage = HANDGUN_DAMAGE;
    shotCounter = 0;
    currentWeapon = 1;
    this.health = PLAYER_HEALTH;
  }
  
  public void draw()
  {
    if (shotCounter > 0)
      shotCounter++;
    currentAmmo = weaponAmmo[currentWeapon-1];
    updateLocation();
  }
  
  private void updateLocation()
  {
   location = gameCamera.getLocation(); 
  }
 
 public void changeWeapon(int weapon)
 {
   if (weapon ==1)
     damage = HANDGUN_DAMAGE;
   else if (weapon == 2)
     damage = MACHINEGUN_DAMAGE;
   else if (weapon == 3)
     damage = SHOTGUN_DAMAGE;
   else if (weapon == 4)
     damage = SNIPER_DAMAGE;
   else if (weapon == 5)
     damage = GRENADE_DAMAGE;
   currentWeapon = weapon;
   shotCounter = 0;
 }
 
 public boolean canShoot()
 {
    if (shotCounter == 0 && currentAmmo > 0)
    {
      shotCounter++;
      weaponAmmo[currentWeapon-1]--;
      return true;
    }
    else if (currentWeapon == 1 && shotCounter > HANDGUN_COUNTER)
      shotCounter = 0;
    else if (currentWeapon == 2 && shotCounter > MACHINEGUN_COUNTER)
      shotCounter = 0;
    else if (currentWeapon == 3 && shotCounter > SHOTGUN_COUNTER)
      shotCounter = 0;
    else if (currentWeapon == 4 && shotCounter > SNIPER_COUNTER)
      shotCounter = 0;
    else if (currentWeapon == 5 && shotCounter > GRENADE_COUNTER)
      shotCounter = 0;  
    
    return false;      
 }
 
 public int getAmmo()
 {
    return currentAmmo; 
 }
 
 public void addAmmo(int weapon, int ammo)
 {
  weaponAmmo[weapon-1] += ammo; 
 }
 
 public void heal(float health)
 {
   this.health += health;
   this.health = constrain(this.health, 0, PLAYER_HEALTH);
 }
 
 //Override
  public void takeDamage(float hit)
  {
    health -= hit;
    this.health = constrain(this.health, 0, PLAYER_HEALTH);
  }
 
 public void reset()
 {
   init();
 }
 
}
